package com.mcglib.flac.buttonGroup
{
	import com.mcglib.flac.DataRender;
	import com.mcglib.flac.FlacUtils;
	
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	
	
	public class SimpleButtonRender extends DataRender
	{
		public function SimpleButtonRender()
		{
			super();
		}
		
		private var srcState:Object;
		override public function set selected(s:Boolean):void{
			if(s==selected)
				return;
			
			var btn:SimpleButton = this.btn;
			
			if(s){
				srcState = {up:btn.upState,over:btn.overState,down:btn.downState};
				btn.upState = btn.downState;
				btn.overState = btn.downState;
				btn.enabled = false;
			}else{
				btn.upState = srcState.up as DisplayObject;
				btn.overState = srcState.over as DisplayObject;
				btn.enabled = true;
			}
			
			super.selected = s;
		}
		
		override public function set selectable(s:Boolean):void{
			super.selectable = s;
			if(btn){
				if(!s)
				{
					FlacUtils.gray(btn);
				}else{
					FlacUtils.cancelGray(btn);	
				}
			}
		}
		
		private function get btn():SimpleButton{
			return ui as SimpleButton;
		}
	}
}